import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
import Cookie from '../cookies/cookies'
Vue.use(VueRouter)


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  let cookie = Cookie.getCookie()
  // let arr = cookie.split('=')
  if (!cookie.username && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
export default router
